﻿using System;
using System.Runtime.CompilerServices;
using UnityEngine;

public static class AssetExtension
{
    public static Asset GetAsset(this Component comp)
    {
        if (comp == null)
        {
            return null;
        }
        AssetReference component = comp.GetComponent<AssetReference>();
        return ((component == null) ? null : AssetManager.GetAsset(component.assetName));
    }

    public static string GetAssetName(this Component comp)
    {
        if (comp == null)
        {
            return null;
        }
        AssetReference component = comp.GetComponent<AssetReference>();
        return ((component == null) ? null : component.assetName);
    }

    public static string GetAssetName(this GameObject go)
    {
        return go.transform.GetAssetName();
    }

    public static string GetLocalizedAssetName(this Component comp)
    {
        Asset asset = comp.GetAsset();
        return ((asset == null) ? null : asset.localizedName);
    }

    public static string GetModelFileName(this Component comp)
    {
        Asset asset = comp.GetAsset();
        return ((asset == null) ? null : asset.modelFileName);
    }
}

